import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonalKeyPage(Base):
    """
    钥匙管理
    """

    # TODO: 钥匙绑定后的状态未遍历(解除绑定>绑定)

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.key_home_btn = (By.XPATH, Personal.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.key_back_btn = (By.XPATH, Personal.RESOURCE_ID.format('ivBack'))

        # 页面_变量名_元素类型
        # 蓝牙钥匙名称
        self.key_bluetooth_name_text = (By.XPATH, Page.TEXT.format("蓝牙钥匙"))

        # 蓝牙钥匙图片
        self.key_bluetooth_image_img = (By.XPATH, Personal.RESOURCE_ID.format("iv_bluetooth_key"))

        # 蓝牙钥匙绑定按钮
        self.key_bluetooth_key_binding_btn = (By.XPATH, Personal.RESOURCE_ID.format("unbind_bluetooth_key_bt"))
        # self.key_bluetooth_binding_btn = (By.XPATH, Page.TEXT.format("绑定"))

        # 普通钥匙名称
        self.key_common_key_name_text = (By.XPATH, Page.TEXT.format("普通钥匙"))

        # 普通钥匙图片
        self.key_common_key_image_img = (By.XPATH, Personal.RESOURCE_ID.format("iv_normal_key"))

        # 普通钥匙解除绑定
        # self.key_normal_key_binding_btn = (By.XPATH, Page.TEXT.format("解除绑定"))
        self.key_normal_unbinding_btn = (By.XPATH, Personal.RESOURCE_ID.format("unbind_normal_key_bt"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.key_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.key_home_btn)

    def get_bluetooth_name(self):
        """
        获取蓝牙钥匙名称

        :return: 元素对象
        """
        return self.find_element_o(self.key_bluetooth_name_text)

    def get_bluetooth_image(self):
        """
        获取蓝牙钥匙图片

        :return: 元素对象
        """
        return self.find_element_o(self.key_bluetooth_image_img)

    def click_bluetooth_key_binding(self):
        """
        点击蓝牙钥匙绑定按钮

        :return: None
        """
        self.click_element(self.key_bluetooth_key_binding_btn)

    def get_common_key_name(self):
        """
        获取普通钥匙名称

        :return:元素对象
        """
        return self.find_element_o(self.key_common_key_name_text)

    def get_common_key_image(self):
        """
        获取普通钥匙图片

        :return:元素对象
        """
        return self.find_element_o(self.key_common_key_image_img)

    def click_normal_key_binding(self):
        """
        点击普通钥匙解除绑定按钮

        :return:None
        """
        self.click_element(self.key_normal_unbinding_btn)

    def is_display_personal_key(self):
        """
        是否进入钥匙管理界面

        :return: bool
        """
        return self.is_display(self.key_bluetooth_name_text)
